export const dateNew = parameter => {
  let _date = new Date(parameter * 1000)
  let Y = _date.getFullYear(),
    m = _date.getMonth() + 1,
    d = _date.getDate(),
    H = _date.getHours(),
    i = _date.getMinutes(),
    s = _date.getSeconds()

  m = m < 10 ? '0' + m : m
  d = d < 10 ? '0' + d : d
  H = H < 10 ? '0' + H : H
  i = i < 10 ? '0' + i : i
  s = s < 10 ? '0' + s : s
  let he = Y + '-' + m + '-' + d + '  ' + H + ':' + i
  return { Y, m, d, H, i, s, he }
}
// sessionStorage封装
export const session = {
  // 存储
  set(key, value) {
    window.sessionStorage.setItem(key, JSON.stringify(value))
  },
  // 获取
  get(key) {
    return JSON.parse(window.sessionStorage.getItem(key))
  },
  // 删除一条
  del(key) {
    window.sessionStorage.removeItem(key)
  },
  // 删除所有
  clear() {
    window.sessionStorage.clear()
  },
}
// localStorage 封装
export const local = {
  keyList: [],
  // 存储
  set(key, value) {
    this.keyList.push(key)
    window.localStorage.setItem(key, JSON.stringify(value))
  },
  // 获取
  get(key) {
    let val = window.localStorage.getItem(key)
    if (val) {
      val = JSON.parse(val)
    }
    return val
  },
  // 删除一条
  del(key) {
    window.localStorage.removeItem(key)
  },
  // 删除所有
  clear() {
    for (let index = 0; index < this.keyList.length; index++) {
      window.localStorage.removeItem(this.keyList[index])
    }
  },
}
//  min 开始   max 结束
export function ranDomRange(min, max) {
  let a = Math.floor(Math.random() * (min - max + 1)) + max
  return a
}

// 获取文件后缀名
export const lastOf = value => {
  if (value === '' || value === undefined) {
    return false
  }
  let laof = value.lastIndexOf('.')
  laof = value.substr(laof + 1)
  return laof
}

export const MapList = new Map([
  ['pdf', '#icon-pdf'],
  ['docx', '#icon-docx'],
  ['doc', '#icon-docx'],
  ['xlsx', '#icon-xlsx1'],
  ['xls', '#icon-xlsx1'],
  ['txt', '#icon-yunpanlogo-2'],
  ['rar', '#icon-yasuobao'],
  ['zip', '#icon-yasuobao'],
  ['7z', '#icon-yasuobao'],
  ['0', '#icon-wenjianjia'],
  ['1', '#icon-weizhiwenjian1'],
  ['jpg', 2],
  ['png', 2],
  ['jpeg', 2],
  ['gif', 2],
  ['JPG', 2],
])
// 转换单位  b到mb
export function Company(params) {
  let a = params / 1024
  if (a <= 1024) {
    return a.toFixed(2) + 'KB'
  }
  a = a / 1024
  return a.toFixed(2) + 'MB'
}

// 文件大小转换 单位
export function sizeZhuanHuan(val) {
  var s = Math.ceil(val / 1024)
  if (s <= 1024) {
    return s + 'KB'
  }
  var si = (s / 1024).toFixed(2) + 'MB'
  return si
}